<!DOCTYPE html>
<html lang="en">
<include file="CommonSidebar:common-head"/>
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>
<link href="__ROOT__/Application/Admin/Public/css/cropper/cropper.min.css" rel="stylesheet">
<link href="__ROOT__/Application/Admin/Public/css/main.css" rel="stylesheet">
<js href="__ROOT__/Application/Admin/Public/ueditor/ueditor.config.js"/>
<js href="__ROOT__/Application/Admin/Public/ueditor/ueditor.all.min.js"/>
<js href="__ROOT__/Application/Admin/Public/js/jquery-2.0.2.js"/>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">有赞团购活动设置</h1>
            </div>
        </div>

        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                            <div class="panel panel-default">
                                <div class="panel-heading" role="tab" id="headingOne">
                                    <h4 class="panel-title">
                                        <a id="TITLEALL" role="button" data-toggle="collapse" data-parent="#accordion"
                                           href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                            添加活动
                                        </a>
                                    </h4>
                                </div>
                                <div id="collapseOne" class="panel-collapse collapse " role="tabpanel"
                                     aria-labelledby="headingOne">
                                    <div class="panel-body">
                                        <form id="editStoreForm" action="{:U('handle')}"
                                              class="form-horizontal"
                                              method="post">
                                            <input type="hidden" id="ID" name="ID">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">团购标题:</label>

                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="TITLE" name="TITLE"
                                                           value="团购 | 你能用一顿KFC的钱买来孩子的幽默感，这就是幸福。">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">团购副标题</label>

                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="F_TITLE"
                                                           name="F_TITLE" value="《小猪小象》双语版 团购价69 下单减免更划算">
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">图片链接:</label>

                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="PIC_URL" name="PIC_URL"
                                                           value="https://h5.youzan.com/v2/goods/36bitpa8zshd7">
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">有赞团购链接:</label>

                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="URL" name="URL"
                                                           value="https://h5.youzan.com/v2/goods/36bitpa8zshd7">
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">书籍原价:</label>

                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="Y_PRICE"
                                                           name="Y_PRICE"
                                                           value="100.4">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">团购价:</label>

                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="TG_PRICE"
                                                           name="TG_PRICE"
                                                           value="65.4">
                                                </div>
                                            </div>


                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">团购结束时间:</label>

                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control" id="S_TIME" name="S_TIME"
                                                           value="2017-12-19">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">是否启用:</label>

                                                <div class="col-sm-3">
                                                    <select class="form-control" name="STATE">
                                                        <option value="1" style="color: #0288f3">启用</option>
                                                        <option value="0" style="color: red">关闭</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-sm-2 ">
                                                    <button type="submit" class="btn btn-block btn-primary">保存</button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">

                <div class="row">
                    <div class="col-md-12">
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center"><input name="all_checkbox" type='checkbox'
                                                                             id="all_checkbox"></th>

                                        <th style="text-align:center" width="15%">团购标题</th>
                                        <th style="text-align:center" width="20%">团购副标题</th>
                                        <th style="text-align:center">图片</th>
                                        <th style="text-align:center" width="20%">有赞团购链接</th>
                                        <th style="text-align:center" width="5%">书籍原价</th>
                                        <th style="text-align:center" width="5%">团购价</th>
                                        <th style="text-align:center"width="8%">团购结束时间</th>
                                        <th style="text-align:center"width="5%">是否启用</th>
                                        <th style="text-align:center"width="5%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="DATA" item="v" key="k">
                                        <tr class="odd gradeX">
                                            <if condition="$v['BOOK_ID']">
                                                <td></td>
                                                <else/>
                                                <td><input type='checkbox' name="checkbox" value="{$v.ID}"></td>
                                            </if>
                                            <td>{$v.TITLE}</td>
                                            <td>{$v.F_TITLE}</td>
                                            <td><img src="{$v.PIC_URL}" width="170px"></td>
                                            <td><a href="{$v.URL}" target="_blank">{$v.URL}</a></td>
                                            <td>{$v.Y_PRICE}</td>
                                            <td>{$v.TG_PRICE}</td>
                                            <td>{$v.S_TIME}</td>
                                            <if condition="$v.STATE == 1">
                                                <td class="changeState" data-id="{$v.ID}">启用</td>
                                                <else/>
                                                <td class="changeState" data-id="{$v.ID}">关闭</td>
                                            </if>
                                            <td> <a onclick="updateA('{$v.ID}','{$v.TITLE}','{$v.F_TITLE}','{$v.PIC_URL}','{$v.URL}','{$v.Y_PRICE}','{$v.TG_PRICE}','{$v.S_TIME}','{$v.STATE}');"
                                                    class="btn btn-warning btn-xs"
                                                    title="Edit">编辑</a>
                                                <a href="javascript:void(0)" onclick="Delete('{$v.ID}',$(this))"
                                                   class="btn btn-danger btn-xs" title="Delete">删除</a>
                                            </td>
                                        </tr>
                                    </foreach>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>

                    </div>
                </div>


            </div>
        </div>

    </div>
    <!-- /#page-wrapper -->

</div>

<include file="CommonSidebar:common-script"/>
<!-- Custom Theme JavaScript -->
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/uploadPreview.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/jquery.form.min.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/jquery.qrcode.min.js"></script>


<include file="Common:common-cropper"/>
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/bootstrapValidator.js"></script>
<script src="__ROOT__/Application/Admin/Public/js/cropper/cropper.min.js"></script>
<script src="__ROOT__/Application/Admin/Public/js/figure.js"></script>


</body>
<script>
    //改变状态
    $(".changeState").click(function () {
        var elem = $(this);
        var state = $(this).html();
        var id = $(this).attr('data-id');
        var statenum = 1;
        var stateStr = '启用';
        if (state == '启用') {
            statenum = 0;
            stateStr = '关闭'
        }
        alert(stateStr);
        $.post("{:U('changeState')}", {STATE: statenum, ID: id}, function (OK) {
            if (OK == 1) {
                elem.html(stateStr);
                alert('修改成功');
            } else {
                if (OK == -1) {
                    alert('已经有已启用的团购活动了，请先确定需要哪个活动再进行添加操作');
                }
                alert('修改失败');
            }

        });
    });
    //删除
    function Delete(ID, elem) {
        if (confirm("确认删除？")) {
            $.post("{:U('Del')}",
                    {ID: ID},
                    function (data) {
                        if (data) {
                            alert('删除成功');
                            elem.parent().parent().remove();
                        } else {
                            alert('删除失败');
                        }
                    });
        }
    }
    //修改
    function updateA(ID,TITLE,F_TITLE,PIC_URL,URL,Y_PRICE,TG_PRICE,S_TIME,A_CREATE_TIME,STATE){
        $('#collapseOne').removeClass('in');
        $('#collapseOne').addClass('in');
        $('#TITLEALL').html('编辑');
        $('#ID').val(ID);
        $('#TITLE').val(TITLE);
        $('#F_TITLE').val(F_TITLE);
        $('#PIC_URL').val(PIC_URL);
        $('#URL').val(URL);
        $('#Y_PRICE').val(Y_PRICE);
        $('#TG_PRICE').val(TG_PRICE);
        $('#S_TIME').val(S_TIME);
        $('#A_CREATE_TIME').val(A_CREATE_TIME);
        $('#STATE').val(STATE);
    }
</script>
<script>

</script>
</html>
